﻿#ifndef _SQLRECORD_H_H_
#define _SQLRECORD_H_H_

#include "udatabase/sqlutility.h"
#include "udatabase/sqlfield.h"
#include "kernel/Referenced.h"

namespace FD{
	namespace Utility{
		namespace DB{

			class CSqlRecordPrivate;
			///<summary>
			///封装字段信息
			///</summary>
			class FD_DB_Export CSqlRecord : public FD::Kernel::CReferenced
			{
			public:
				///<summary>
				///默认构造函数
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				CSqlRecord();
				///<summary>
				///拷贝构造函数
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlRecord对象</param>
				///<returns></returns>
				CSqlRecord(const CSqlRecord& other);
				///<summary>
				///重载赋值操作符
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlRecord对象</param>
				///<returns></returns>
				FD::Utility::DB::CSqlRecord& operator=(const FD::Utility::DB::CSqlRecord& other);
				///<summary>
				///析构函数
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				~CSqlRecord();
				///<summary>
				///赋值操作符==的重载
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlRecord对象</param>
				///<returns></returns>
				bool operator==(const FD::Utility::DB::CSqlRecord &other) const;
				///<summary>
				///赋值操作符!=的重载
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlRecord对象</param>
				///<returns></returns>
				bool operator!=(const FD::Utility::DB::CSqlRecord &other) const { return !operator==(other); }
				///<summary>
				///当前索引位置的字段值
				///</summary>
				///<param name="i">字段索引</param>
				///<returns>字段值</returns>
				FD::Kernel::Variant value(INT32 i) const;
				///<summary>
				///字段name的值
				///</summary>
				///<param name="name">字段名</param>
				///<returns>字段值</returns>
				FD::Kernel::Variant value(const FD::Kernel::FdUnicodeString& name) const;
				///<summary>
				///设置在i字段的字段值
				///</summary>
				///<param name="i">字段索引</param>
				///<param name="val">字段值</param>
				///<returns></returns>
				void setValue(INT32 i, const FD::Kernel::Variant& val);
				///<summary>
				///设置name字段的字段值
				///</summary>
				///<param name="i">字段名</param>
				///<param name="val">字段值</param>
				///<returns></returns>
				void setValue(const FD::Kernel::FdUnicodeString& name, const FD::Kernel::Variant& val);
				///<summary>
				///设置i字段为空
				///</summary>
				///<param name="i">字段索引</param>
				///<returns></returns>
				void setNull(INT32 i);
				///<summary>
				///设置name字段为空
				///</summary>
				///<param name="name">字段名</param>
				///<returns></returns>
				void setNull(const FD::Kernel::FdUnicodeString& name);
				///<summary>
				///i字段是否为空
				///</summary>
				///<param name="i">字段索引</param>
				///<returns>为空返回true,否则返回false</returns>
				bool isNull(INT32 i) const;
				///<summary>
				///name字段是否为空
				///</summary>
				///<param name="name">字段名</param>
				///<returns>为空返回true,否则返回false</returns>
				bool isNull(const FD::Kernel::FdUnicodeString& name) const;
				///<summary>
				///name字段的索引号
				///</summary>
				///<param name="name">字段名</param>
				///<returns>索引号</returns>
				INT32 indexOf(const FD::Kernel::FdUnicodeString &name) const;
				///<summary>
				///索引为i的字段名
				///</summary>
				///<param name="i">索引号</param>
				///<returns>字段名</returns>
				FD::Kernel::FdUnicodeString fieldName(INT32 i) const;
				///<summary>
				///索引为i的字段
				///</summary>
				///<param name="i">索引号</param>
				///<returns>字段</returns>
				FD::Utility::DB::CSqlField field(INT32 i) const;
				///<summary>
				///获取字段名为name的字段
				///</summary>
				///<param name="name">字段</param>
				///<returns>字段</returns>
				FD::Utility::DB::CSqlField field(const FD::Kernel::FdUnicodeString &name) const;

				bool isGenerated(INT32 i) const;
				bool isGenerated(const FD::Kernel::FdUnicodeString& name) const;
				void setGenerated(const FD::Kernel::FdUnicodeString& name, bool generated);
				void setGenerated(INT32 i, bool generated);
				///<summary>
				///最佳字段
				///</summary>
				///<param name="field">字段</param>
				///<returns></returns>
				void append(const FD::Utility::DB::CSqlField& field);
				///<summary>
				///替换在pos处的字段
				///</summary>
				///<param name="pos">索引号</param>
				///<param name="field">字段</param>
				///<returns></returns>
				void replace(INT32 pos, const FD::Utility::DB::CSqlField& field);
				///<summary>
				///在pos处插入字段
				///</summary>
				///<param name="pos">索引号</param>
				///<param name="field">字段</param>
				///<returns></returns>
				void insert(INT32 pos, const FD::Utility::DB::CSqlField& field);
				///<summary>
				///删除在pos处的字段
				///</summary>
				///<param name="pos">索引号</param>
				///<returns></returns>
				void remove(INT32 pos);
				///<summary>
				///字段数是否为0
				///</summary>
				///<param name=""></param>
				///<returns>为0返回true,否则返回false</returns>
				bool isEmpty() const;
				///<summary>
				///是否包含字段名为name的字段
				///</summary>
				///<param name="name">字段名</param>
				///<returns>包含返回true,否则返回false</returns>
				bool contains(const FD::Kernel::FdUnicodeString& name) const;
				///<summary>
				///删除所有字段
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				void clear();
				///<summary>
				///删除所有字段值并将值设为空
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				void clearValues();
				///<summary>
				///字段数
				///</summary>
				///<param name=""></param>
				///<returns>字段数</returns>
				INT32 count() const;

			private:
				void detach();
				CSqlRecordPrivate *m_private;
			};

		} // namespace Database
	} 
}

#endif //_SQLRECORD_H_H_

